/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ORDB4ORA.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import ORDB4ORA.ORDB4ORAPackage;
import ORDB4ORA.Restriction;
import ORDB4ORA.StructuralComponent;
import ORDB4ORA.Table;
import ORDB4ORA.util.derivedAttributeAdapter;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Restriction</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ORDB4ORA.impl.RestrictionImpl#getAttributes <em>Attributes</em>}</li>
 *   <li>{@link ORDB4ORA.impl.RestrictionImpl#getTable <em>Table</em>}</li>
 *   <li>{@link ORDB4ORA.impl.RestrictionImpl#getName <em>Name</em>}</li>
 *   <li>{@link ORDB4ORA.impl.RestrictionImpl#getNameColumns <em>Name Columns</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class RestrictionImpl extends EObjectImpl implements
		Restriction {
	/**
	 * The cached value of the '{@link #getAttributes() <em>Attributes</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAttributes()
	 * @generated
	 * @ordered
	 */
	protected EList<StructuralComponent> attributes;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = "";

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getNameColumns() <em>Name Columns</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNameColumns()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_COLUMNS_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getNameColumns() <em>Name Columns</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNameColumns()
	 * @generated
	 * @ordered
	 */
	protected String nameColumns = NAME_COLUMNS_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * 
	 */
	protected RestrictionImpl() {
		super();
		derivedAttributeAdapter daa = new derivedAttributeAdapter(this,
				ORDB4ORAPackage.RESTRICTION__NAME_COLUMNS);
		daa.addNavigatedDependency(ORDB4ORAPackage.RESTRICTION__ATTRIBUTES,
				ORDB4ORAPackage.STRUCTURAL_COMPONENT__NAME);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ORDB4ORAPackage.Literals.RESTRICTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Table getTable() {
		if (eContainerFeatureID != ORDB4ORAPackage.RESTRICTION__TABLE)
			return null;
		return (Table) eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTable(Table newTable,
			NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject) newTable,
				ORDB4ORAPackage.RESTRICTION__TABLE, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTable(Table newTable) {
		if (newTable != eInternalContainer()
				|| (eContainerFeatureID != ORDB4ORAPackage.RESTRICTION__TABLE && newTable != null)) {
			if (EcoreUtil.isAncestor(this, newTable))
				throw new IllegalArgumentException(
						"Recursive containment not allowed for " + toString()); //$NON-NLS-1$
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newTable != null)
				msgs = ((InternalEObject) newTable).eInverseAdd(this,
						ORDB4ORAPackage.TABLE__RESTRICTION, Table.class, msgs);
			msgs = basicSetTable(newTable, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					ORDB4ORAPackage.RESTRICTION__TABLE, newTable, newTable));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					ORDB4ORAPackage.RESTRICTION__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<StructuralComponent> getAttributes() {
		if (attributes == null) {
			attributes = new EObjectWithInverseResolvingEList.ManyInverse<StructuralComponent>(
					StructuralComponent.class, this,
					ORDB4ORAPackage.RESTRICTION__ATTRIBUTES,
					ORDB4ORAPackage.STRUCTURAL_COMPONENT__RESTRICTIONS);
		}
		return attributes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 *@generated NOT
	 *
	 */
	public String getNameColumns() {
		String nNombre = new String("");
		if (this.attributes != null) {
			for (int i = 0; i < this.attributes.size(); i++) {
				if (i == this.attributes.size() - 1) {
					nNombre = nNombre + this.attributes.get(i).getName();
				} else {
					nNombre = nNombre + this.attributes.get(i).getName() + ", ";
				}
			}
		}
		nameColumns = nNombre;
		return nameColumns;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 * 
	 */
	public void setNameColumns(String newNameColumns) {
		String oldNameColumns = nameColumns;
		//nameColumns = newNameColumns;
		String nNombre = new String("");
		if (this.attributes != null) {
			for (int i = 0; i < this.attributes.size(); i++) {
				if (i == this.attributes.size() - 1) {
					nNombre = nNombre + this.attributes.get(i).getName();
				} else {
					nNombre = nNombre + this.attributes.get(i).getName() + ", ";
				}
			}
		}
		nameColumns = nNombre;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					ORDB4ORAPackage.RESTRICTION__NAME_COLUMNS, oldNameColumns,
					nameColumns));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * 
	 */
	public void setNombre(String newNombre) {
		String oldNombre = nameColumns;
		//nombre = newNombre;
		String nNombre = new String("");
		for (int i = 0; i < this.attributes.size(); i++) {
			nNombre = nNombre + this.attributes.get(i).getName() + ", ";
		}
		nameColumns = nNombre;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					ORDB4ORAPackage.RESTRICTION__NAME_COLUMNS, oldNombre,
					nameColumns));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case ORDB4ORAPackage.RESTRICTION__ATTRIBUTES:
			return ((InternalEList<InternalEObject>) (InternalEList<?>) getAttributes())
					.basicAdd(otherEnd, msgs);
		case ORDB4ORAPackage.RESTRICTION__TABLE:
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			return basicSetTable((Table) otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case ORDB4ORAPackage.RESTRICTION__ATTRIBUTES:
			return ((InternalEList<?>) getAttributes()).basicRemove(otherEnd,
					msgs);
		case ORDB4ORAPackage.RESTRICTION__TABLE:
			return basicSetTable(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(
			NotificationChain msgs) {
		switch (eContainerFeatureID) {
		case ORDB4ORAPackage.RESTRICTION__TABLE:
			return eInternalContainer().eInverseRemove(this,
					ORDB4ORAPackage.TABLE__RESTRICTION, Table.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case ORDB4ORAPackage.RESTRICTION__ATTRIBUTES:
			return getAttributes();
		case ORDB4ORAPackage.RESTRICTION__TABLE:
			return getTable();
		case ORDB4ORAPackage.RESTRICTION__NAME:
			return getName();
		case ORDB4ORAPackage.RESTRICTION__NAME_COLUMNS:
			return getNameColumns();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case ORDB4ORAPackage.RESTRICTION__ATTRIBUTES:
			getAttributes().clear();
			getAttributes().addAll(
					(Collection<? extends StructuralComponent>) newValue);
			return;
		case ORDB4ORAPackage.RESTRICTION__TABLE:
			setTable((Table) newValue);
			return;
		case ORDB4ORAPackage.RESTRICTION__NAME:
			setName((String) newValue);
			return;
		case ORDB4ORAPackage.RESTRICTION__NAME_COLUMNS:
			setNameColumns((String) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case ORDB4ORAPackage.RESTRICTION__ATTRIBUTES:
			getAttributes().clear();
			return;
		case ORDB4ORAPackage.RESTRICTION__TABLE:
			setTable((Table) null);
			return;
		case ORDB4ORAPackage.RESTRICTION__NAME:
			setName(NAME_EDEFAULT);
			return;
		case ORDB4ORAPackage.RESTRICTION__NAME_COLUMNS:
			setNameColumns(NAME_COLUMNS_EDEFAULT);
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case ORDB4ORAPackage.RESTRICTION__ATTRIBUTES:
			return attributes != null && !attributes.isEmpty();
		case ORDB4ORAPackage.RESTRICTION__TABLE:
			return getTable() != null;
		case ORDB4ORAPackage.RESTRICTION__NAME:
			return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT
					.equals(name);
		case ORDB4ORAPackage.RESTRICTION__NAME_COLUMNS:
			return NAME_COLUMNS_EDEFAULT == null ? nameColumns != null
					: !NAME_COLUMNS_EDEFAULT.equals(nameColumns);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (Name: "); //$NON-NLS-1$
		result.append(name);
		result.append(", NameColumns: "); //$NON-NLS-1$
		result.append(nameColumns);
		result.append(')');
		return result.toString();
	}

} //RestrictionImpl
